package frontend.pages.reports.commuter;

import frontend.model.reports.CommutersReportEntry;
import org.apache.wicket.Localizer;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.model.Model;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

public class CommutersReportTableTemplate implements Serializable {

    public static final String RESOURCE_KEY_TABLE_HEADER_IDENTIFICATION_CARD = "table.header.identificationCard";
    private static final String RESOURCE_KEY_TABLE_HEADER_EMPLOYEE = "table.header.employee";
    private static final String RESOURCE_KEY_TABLE_HEADER_DAYS_WITH_NORMAL_HOURS = "table.header.daysWithNormalHours";
    private static final String RESOURCE_KEY_TABLE_HEADER_DAYS_WITH_EXTRA_HOURS = "table.header.daysWithExtraHours";

    protected List<IColumn<CommutersReportEntry>> columns = new LinkedList<IColumn<CommutersReportEntry>>();
    protected List<String> header = new LinkedList<String>();

    public CommutersReportTableTemplate() {
        createColumns();
    }

    public List<IColumn<CommutersReportEntry>> getColumns() {
        return columns;
    }

    public List<String> getHeader() {
        return header;
    }

    protected void createColumns() {
        columns.add(getIdentificationCardColumn());
        columns.add(getEmployeeColumn());
        columns.add(getDaysWithNormalHoursColumn());
        columns.add(getDaysWithOvertimeColumn());
    }

    protected AbstractColumn<CommutersReportEntry> getEmployeeColumn() {
        String columnName = Localizer.get().getString(RESOURCE_KEY_TABLE_HEADER_EMPLOYEE, null);
        header.add(columnName);
        return new PropertyColumn<CommutersReportEntry>(new Model<String>(columnName), "employee", "employee");
    }

    protected AbstractColumn<CommutersReportEntry> getIdentificationCardColumn() {
        String columnName = Localizer.get().getString(RESOURCE_KEY_TABLE_HEADER_IDENTIFICATION_CARD, null);
        header.add(columnName);
        return new PropertyColumn<CommutersReportEntry>(new Model<String>(columnName), "identificationCard", "identificationCard");
    }

    protected AbstractColumn<CommutersReportEntry> getDaysWithNormalHoursColumn() {
        String columnName = Localizer.get().getString(RESOURCE_KEY_TABLE_HEADER_DAYS_WITH_NORMAL_HOURS, null);
        header.add(columnName);
        return new PropertyColumn<CommutersReportEntry>(new Model<String>(columnName), "daysWithNormalHours", "daysWithNormalHours");
    }

    protected AbstractColumn<CommutersReportEntry> getDaysWithOvertimeColumn() {
        String columnName = Localizer.get().getString(RESOURCE_KEY_TABLE_HEADER_DAYS_WITH_EXTRA_HOURS, null);
        header.add(columnName);
        return new PropertyColumn<CommutersReportEntry>(new Model<String>(columnName), "daysWithOvertime", "daysWithOvertime");
    }
}
